﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace SuperKit {
    public class DirectoryReaderItem {
        public string Name { get; set; }
        public string FullPath { get; set; }

        public DirectoryReaderItem(string path) {
            Name = Path.GetFileName(path);
            FullPath = path;
        }

        public override string ToString() {
            return Name;
        }
    }

    public class DirectoryReader {
        

        private static DirectoryReader _instance;
        public static DirectoryReader Inst => _instance ?? (_instance = new DirectoryReader());
        public List<DirectoryReaderItem> Items;

        public DirectoryReader() {
            Items = new List<DirectoryReaderItem>();
        }

        public void SetDirectory(string dir) {
            Items.Clear();
            DirectoryInfo info = new DirectoryInfo(Path.GetDirectoryName(dir));
            try {
                var dirs = info.GetDirectories();
                foreach (var i in dirs) {
                    Items.Add(new DirectoryReaderItem(i.FullName));
                }
            } catch (IOException) {
                return;
            }
            
        }

        public void Fill(ListBox box) {
            foreach (var i in Items) {
                box.Items.Add(i);                
            }
        }
    }
}
